//! \file WindowDice.cpp
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include "Elements.h"
#include "GuiCEGUI.h"
#include <stddef.h>

using namespace CEGUI;

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================

// =====[ Local Functions ]=====================================================

// =====[ Private (Internal) Methods ]==========================================

// =====[ Local Implementation ]================================================








// Sample sub-class for ListboxTextItem that auto-sets the selection brush
// image.  This saves doing it manually every time in the code.
class MyListItem : public CEGUI::ListboxTextItem
{
public:
    MyListItem(const CEGUI::String& text) : ListboxTextItem(text)
    {
        setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
    }
};






// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
tERROR WindowDice::create(Window *pParent)
{
//  Window *pWindow;

// TODO: resolve this issue
//  // We can only create one dice window.
//  if (createSingle(pParent) == false)
//    { return (ERR_GUI_UNABLE_TO_CREATE); }

  // If no parent was provided, we will attach it to the root.
  if (pParent == NULL) { pParent = GuiCEGUI::getRoot(); }

  // Load the console window layout and add it to the parent.
  pParent->addChildWindow(GuiCEGUI::getWm()->loadWindowLayout("DQ_Dice.layout"));

  Window* pWindow = static_cast<Window*>(GuiCEGUI::getWm()->getWindow("Dice"));

  pWindow->setPosition(UVector2(UDim(0.25f, 0.0f), UDim(0.25f, 0.0f)));

  Combobox* cbobox = static_cast<Combobox*>(GuiCEGUI::getWm()->getWindow("Dice/Combobox"));
  // add items to the combobox list
  cbobox->addItem(new MyListItem("1d6"));
  cbobox->addItem(new MyListItem("1d8"));
  cbobox->addItem(new MyListItem("2d8"));
  cbobox->addItem(new MyListItem("1d20"));
  cbobox->addItem(new MyListItem("1d6+2"));
  cbobox->addItem(new MyListItem("1d6+1d8"));


  // Roll button.
//  subscribeEvent("Dice/Roll", PushButton::EventClicked, SubscriberSlot(&eventRoll));

//  // Clear button.
//  subscribeEvent("Console/Clear", PushButton::EventClicked, SubscriberSlot(&eventClear));

  // Return success.
  return (ERR_NONE);
}


bool WindowDice::eventRoll(const CEGUI::EventArgs& Event)
{

//
//  Text.String("Roll");

  puts("Roll");

//  WindowConsole::appendText(String("Roll"));

  // Return the event was handled.
  return (true);
}



